//
//  MeViewController.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/3.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//
#import "MeViewController.h"
#import "CommonMacro.h"
#import "HeaderView.h"
#import "AddThreeButtonView.h"
#import "TrailView.h"
#import "MyOrderView.h"
#import "AboutOurView.h"

#import "SetPersonMessageVC.h"

#import "DetailTrialViewController.h"
#import "TrailReportsViewController.h"


#import "MyOrderModel.h"

@interface MeViewController ()<enterDifferentDelegate,enterSetCenterDelegate,applyHaveViewDelegate,reportTraSideBarDelegate>

{
    HeaderView *headerView;
    AddThreeButtonView *addThreeButtonView;
    TrailView *trailView;
    MyOrderView *myOrderView;
    AboutOurView *aboutOurView;
}

@property (nonatomic,strong) NSArray *faluseArray;
@end

@implementation MeViewController

//延迟实例化
- (NSMutableArray *)contentArr
{
    if (_contentArr==nil) {
        _contentArr = [[NSMutableArray alloc] init];
    }
    return _contentArr;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;

    
// 假数据部分
    self.faluseArray = [[NSArray alloc] init];
    self.faluseArray = @[@{@"orderNumber":@"23u3408y5384t348t",@"img":@"http://www.mmisy.com/data/upload/shop/store/goods/1/1_04858630694320708_240.jpg",@"description":@"婴儿推车高景观 避震充气轮 婴儿车可躺可坐 BB折叠手推车",@"other":@"红色",@"amount":@"1",@"price":@"￥358元"},@{@"orderNumber":@"23u3408y5384t348t",@"img":@"http://www.mmisy.com/data/upload/shop/store/goods/1/1_04858630694320708_240.jpg",@"description":@"婴儿推车高景观 避震充气轮 婴儿车可躺可坐 BB折叠手推车",@"other":@"红色",@"amount":@"1",@"price":@"￥358元"},@{@"orderNumber":@"23u3408y5384t348t",@"img":@"http://www.mmisy.com/data/upload/shop/store/goods/1/1_04858630694320708_240.jpg",@"description":@"婴儿推车高景观 避震充气轮 婴儿车可躺可坐 BB折叠手推车",@"other":@"红色",@"amount":@"1",@"price":@"￥358元"},@{@"orderNumber":@"23u3408y5384t348t",@"img":@"http://www.mmisy.com/data/upload/shop/store/goods/1/1_04858630694320708_240.jpg",@"description":@"婴儿推车高景观 避震充气轮 婴儿车可躺可坐 BB折叠手推车",@"other":@"红色",@"amount":@"1"},@{@"orderNumber":@"23u3408y5384t348t",@"img":@"http://www.mmisy.com/data/upload/shop/store/goods/1/1_04858630694320708_240.jpg",@"description":@"婴儿推车高景观 避震充气轮 婴儿车可躺可坐 BB折叠手推车",@"other":@"红色",@"amount":@"1",@"price":@"￥358元"}];
    for (int i = 0; i<self.faluseArray.count; i++) {
        MyOrderModel *myOrderModel = [[MyOrderModel alloc] init];
        [myOrderModel decodedic:self.faluseArray[i]];
        [self.contentArr addObject:myOrderModel];
    }
    
//    [myOrderView.tableView reloadData];
    //添加子视图
    [self addSubViews];

}

#pragma mark 添加视图
- (void)addSubViews
{
    //0.添加一个scrollView
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT*1.28);
    [self.view addSubview:self.scrollView];
    self.scrollView.showsVerticalScrollIndicator = NO;
    
    //1.添加头部内容
    headerView = [[HeaderView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH, SCREEN_HEIGHT*0.28)];
    headerView.backgroundColor = [UIColor redColor];
    headerView.delegate = self;
    [self.scrollView addSubview:headerView];
    
    //2.添加三个button
    addThreeButtonView = [[AddThreeButtonView alloc] initWithFrame:CGRectMake(headerView.frame.origin.x, headerView.frame.size.height, SCREEN_WIDTH, SCREEN_HEIGHT*0.1)];
    addThreeButtonView.delegate = self;
//    addThreeButtonView.backgroundColor = [UIColor blueColor];
    [self.scrollView addSubview:addThreeButtonView];

    //3.1我的订单
    myOrderView = [[MyOrderView alloc] initWithFrame:CGRectMake(0, addThreeButtonView.frame.size.height+addThreeButtonView.frame.origin.y, SCREEN_WIDTH, SCREEN_HEIGHT*0.9)];
//    myOrderView.recieveArray = self.contentArr;
    myOrderView.backgroundColor = [UIColor redColor];
    NSLog(@"myOrderView :%@",NSStringFromCGRect(myOrderView.frame));
    [self.scrollView addSubview:myOrderView];
    
    //3.2关于我们
    aboutOurView = [[AboutOurView alloc] initWithFrame:CGRectMake(0, addThreeButtonView.frame.size.height+addThreeButtonView.frame.origin.y, SCREEN_WIDTH, SCREEN_HEIGHT*0.9)];
//    aboutOurView.backgroundColor = [UIColor blueColor];
    [self.scrollView addSubview:aboutOurView];

}

#pragma mark 
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    trailView = [[TrailView alloc] init];
    trailView.frame = CGRectMake(0, addThreeButtonView.frame.size.height+addThreeButtonView.frame.origin.y, SCREEN_WIDTH, SCREEN_HEIGHT*0.8);
//    trailView.delegate = self;
    trailView.applayDelegate = self;
    trailView.reportTraDelegate = self;
    trailView.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:trailView];
    
}

#pragma mark enterSetCenterDelegate
- (void)enterSetCenter
{
    SetPersonMessageVC *setPersonM = [[SetPersonMessageVC alloc] init];
    UINavigationController *setPerMesNav = [[UINavigationController alloc] initWithRootViewController:setPersonM];
    [self presentViewController:setPerMesNav animated:YES completion:nil];
}

#pragma mark enterDifferentDelegate
- (void)enterDifferent:(UIButton *)tagButton
{
    if (addThreeButtonView.lastBtn!=tagButton) {
        addThreeButtonView.lastBtn.selected = NO;
    }
    addThreeButtonView.lastBtn=tagButton;
    tagButton.selected=YES;
    if (tagButton.tag==100) {
        [self.scrollView bringSubviewToFront:trailView];
        addThreeButtonView.trailLine.hidden = NO;
        addThreeButtonView.orderLine.hidden = YES;
        addThreeButtonView.aboutourLine.hidden = YES;
    }
    else if (tagButton.tag==101)
    {
        [self.scrollView bringSubviewToFront:myOrderView];
        addThreeButtonView.trailLine.hidden = YES;
        addThreeButtonView.orderLine.hidden = NO;
        addThreeButtonView.aboutourLine.hidden = YES;
    }
    else
    {
        [self.scrollView bringSubviewToFront:aboutOurView];
        addThreeButtonView.trailLine.hidden = YES;
        addThreeButtonView.orderLine.hidden = YES;
        addThreeButtonView.aboutourLine.hidden = NO;
    }
}

#pragma mark  点击某一行  进行跳转 applyHaveViewDelegate
- (void)applyHaveSideBar:(TrailView *)sideBar didSelectAtIndex:(NSInteger)index
{
    NSLog(@"点击了第几行 已申请");
    DetailTrialViewController *detailTrialView = [[DetailTrialViewController alloc] init];
    UINavigationController *detailTrialViewNav = [[UINavigationController alloc] initWithRootViewController:detailTrialView];
    [self presentViewController:detailTrialViewNav animated:YES completion:nil];
}

#pragma mark reportTraSideBarDelegate 点击试用报告后会进入的界面
- (void)reportTraSideBarRe:(ReportVIew *)sideBar didSelectAtIndex:(NSInteger)index
{
    NSLog(@"shiyongbaogao  点击");
    
    TrailReportsViewController *trailReport = [[TrailReportsViewController alloc] init];
    UINavigationController *trailReportNavi = [[UINavigationController alloc] initWithRootViewController:trailReport];
    [self presentViewController:trailReportNavi animated:YES completion:nil];
}

@end
